﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TemaIP_cars
{
    class Program
    {
        static void Main(string[] args)
        {

            FabricaSedan sedanPool = new FabricaSedan();
            FabricaMini   miniPool = new FabricaMini();
            FabricaCoupe coupePool = new FabricaCoupe();

            for (int i = 0; i < 10; i++)
            {
                sedanPool.Put(new Sedan());
                coupePool.Put(new Coupe());
                miniPool.Put(new Mini());
            }

            //se creeaza o lista de clienti
            List<Client> clienti = new List<Client>();
            clienti.Add(new Client("Nume1", 30));
            clienti.Add(new Client("Nume2", 35));
            clienti.Add(new Client("Nume3", 40));
            clienti.Add(new Client("Nume4", 45));
            clienti.Add(new Client("Nume5", 50));

            Console.WriteLine("Numele clientilor disponibili:");
            foreach (Client c in clienti) Console.Write(c.getNume() + " | ");
            Console.WriteLine();
            
            getOption:
            Console.Write("\n1 - adaugare masina\n2 - stergere masina\n3 - exit\n\nOptiune: ");
            string optiune = Console.ReadLine();

            Masina m;
            string tip;
            string numeClient;

            switch (optiune)
            { 
                    //////////////////////////////////////Adaugarea unei masini in lista unui client
                case "1":
                    Console.WriteLine("\nAdaugarea unei masini\n\n");
                    getTip:
                    Console.Write("Tip masina (sedan / coupe / mini):");
                    tip=Console.ReadLine();
                    if (tip != "sedan" && tip != "coupe" && tip != "mini")
                    {
                        Console.WriteLine("-> Tip de masina invalid!...Mai incercati o data...");
                        goto getTip;
                    }

                   switch(tip)
                   {
                       case "sedan":
                               m = sedanPool.Get();
                               m.readInfo();
                               break;
                       case "coupe":
                               m = coupePool.Get();
                               m.readInfo();
                               break;
                       case "mini":
                               m = miniPool.Get();
                               m.readInfo();
                               break;
                       default: 
                           m = sedanPool.Get();
                           m.readInfo();
                           break;
                   }

                    getNumeClient:
                    Console.Write("Nume client: ");
                    numeClient=Console.ReadLine();
                    foreach(Client c in clienti)
                    {
                        if (c.getNume() == numeClient)
                        {
                            c.adaugaMasina(m);
                            c.afisareLista();
                            goto adaugareCompleta;
                        }
                    }

                    Console.WriteLine("-> Clientul " + numeClient + " nu exista!...\n-> Numele clientilor disponibili:");
                    Console.Write("-> ");
                    foreach(Client c in clienti)Console.Write(c.getNume() + " | ");
                    Console.WriteLine("\n-> Mai incercati o data...");
                    goto getNumeClient;

                    adaugareCompleta:
                    break;

                    ////////////////////////////////////////Stergerea unei masini din lista unui client
                case "2":
                    Console.WriteLine("\nStergerea unei masini\n\n");
                    getNumeClient2:
                    Console.Write("Nume client: ");
                    numeClient=Console.ReadLine();

                    foreach(Client c in clienti)
                    {
                        if (c.getNume() == numeClient)
                        { 
                            m=c.stergeMasina();
                            if (m != null)
                            {
                                if (m is Sedan) sedanPool.Put(m as Sedan);
                                if (m is Coupe) coupePool.Put(m as Coupe);
                                if (m is Mini)  miniPool.Put(m as Mini);
                            }
                                
                            c.afisareLista();
                            goto stergereCompleta;
                        }
                    }

                    Console.WriteLine("-> Clientul " + numeClient + " nu exista!...\n-> Numele clientilor disponibili:");
                    Console.Write("-> ");
                    foreach(Client c in clienti)Console.Write(c.getNume() + " | ");
                    Console.WriteLine("\n-> Mai incercati o data...");
                    goto getNumeClient2;

                    stergereCompleta:
                    break;

                    ////////////////////////////iesirea din aplicatie
                case "3":
                    goto leave;
                    //break;
                default:
                    Console.WriteLine("-> Optiune invalida!...Mai incercati o data...\n");
                    goto getOption;
            }
            goto getOption;

            leave:
            Console.Write("\n\nPress any key to continue...");
            Console.ReadKey();
        }
    
    }
}
